<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="memory.*,java.lang.management.ThreadInfo;"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<script type="text/javascript" src="<%= getServletContext().getContextPath() %>/js/scripts.js"></script>
<script type="text/javascript" src="<%= getServletContext().getContextPath() %>/js/jquery-1.2.1.js"></script>
<link rel="stylesheet" type="text/css" href="<%= getServletContext().getContextPath() %>/css/style.css" >
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
  $(document).ready(function(){
        $("div").slideDown("slow");
    });
 </script>
</head>
<%
	ThreadInformation tinfo=(ThreadInformation)request.getAttribute("thread");
	String spid=(String)request.getAttribute("pid");
	if (spid==null){
		long[] tabIds=tinfo.getAllThreadsId();
%>
<body>
<div class="title"> Threads </div>
<div class="info">
<table>
  	<tr>

		<td><b>Virtual Machine supports CPU measuring for any thread:</b></td><td> <%= tinfo.getIsCPU()%></td>

	 </tr>
	 
	  <tr>
	 	<td><b>Total Thread</b></td>
	 	<td><%= tinfo.getTmxbean().getPeakThreadCount() %> </td>
	 </tr>
	  <tr>
	 	<td><b>Number of Daemons</b></td>
	 	<td><%= tinfo.getTmxbean().getDaemonThreadCount() %> </td>
	 </tr>
	 <% TimeManagement tm; %>
	 <tr>
	 	<td><b>Current Thread CPU time:</b></td>
	 	<td><% tm=new TimeManagement(tinfo.getTmxbean().getCurrentThreadCpuTime());%>
	 	<%= tm.getDate() %> 
	 	</td>
	 </tr>
	 <tr>
	 	<td><b>Current Thread User time:</b></td>
	 	<td><%tm.setMilisec(tinfo.getTmxbean().getCurrentThreadUserTime());%>
	 		<%=tm.getDate() %>
	 	</td>
	 </tr>
	<tr>
		<td colspan=2 align=center>
			<b>List of Threads</b>
		</td>
	</tr>
	 <tr>
	 	<td colspan=2>
	 		<ul>
	 		<%
	 			for (int i=0; i<tinfo.getNbThreads();i++){%>
	 					<%
	 						ThreadInfo info=tinfo.getThreadInfo(tabIds[i]);	
	 					%>
	 					<li>
	 						<a href="ThreadInfoP?pid=<%= tabIds[i]%>"> <%= info.getThreadName() %></a>
	 						
	 					</li>
	 			<%}
	 			%>
	 		</ul>
	 	</td>
	 </tr>
	 
</table>
</div>
</body>
<%	}
	else{
%>
	<body>
		<%
			//ThreadInformation tinf=(ThreadInformation) request.getAttribute("thread");
			long pid=Long.parseLong(spid);
			ThreadInfo tt=tinfo.getThreadInfo(pid);
		%>
		<div class="title"> Threads </div>
		<div class="info">
			<table>
				<tr>
					<td>
						<b>PID:</b> <%= spid%>
					</td>
				</tr>
				<tr>
					<td>
						<b>Name:</b> <%= tt.getThreadName()%>
					</td>
				</tr>
				<tr>
					<td>
						<b>State:</b> <%= tt.getThreadState().name()%> on <%= tt.getLockName() %>
					</td>
				</tr>
				<tr>
					<td>
						<b>Total blocked</b> <%= tt.getBlockedCount()%>
					</td>
				</tr>
				<tr>
					<td>
						<b>Total waited:</b> <%= tt.getWaitedCount()%>
					</td>
				</tr>
				<tr>
					<td>
						<b>Stack trace :</b>
					</td>
				</tr>
				<tr>
					<td>
						<ul>
				<% StackTraceElement[] ste=tinfo.getStackTrace(pid); 
				for(int i=0; i<ste.length;i++){ %>
						<li><%= ste[i].getClassName()%>.<%= ste[i].getMethodName()%>
							(<%=ste[i].getFileName() %>:<%= ste[i].getLineNumber() %>)
						</li> 
				<%} %>
						</ul>
					</td>
				</tr>
			</table>
		</div>
	</body>
	<%}%>
</html>